package com.hf.init

import com.hf.date.DateUtils
import com.hf.fetch.UserFetchSummaryService
import com.hf.order.OrderPeriodService
import com.hf.security.OrderUser
import com.hf.security.OrderUserService
import com.hf.security.SystemConfigService

class InitService {

	SystemConfigService systemConfigService
	UserFetchSummaryService userFetchSummaryService
	OrderPeriodService orderPeriodService
	OrderUserService orderUserService

	void init() {
		systemConfigService.init()

		orderPeriodService.getCurrentOrderPeriod(DateUtils.getPeriodStartEndDay())
	}
 
	void endFetch() {
		systemConfigService.setDefaultValueIsRainDay()
	}

	void saveUser(String name, boolean isOrderFrequent, String password, String email) {
		OrderUser user = OrderUser.findByName(name)
		if (!user) {
			user = new OrderUser(name : name, isOrderFrequent: isOrderFrequent, password : password, email : email)
			user.save()
		}
	}
}
